<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>后台登陆</title>
    <link rel="stylesheet" href="/css/layui.css">
    <script src="/layui.js"></script>
    <style>
        body,html{
            height: 100%;
            margin: 0;
            padding: 0;
        }
        body{
            display: flex;
            align-items: center;
            justify-content: center;
            background: url("/bg.jpg") no-repeat;
            background-size:100% 100%;
            
        }
       .box{
            width: 500px;
            height: 250px;
            background-color: rgba(0,0,0,.4);
            position: relative;
            left: 400px;
            padding: 30px;
       }
       h2{
           color: honeydew;
           text-align: center;
           margin-bottom: 30px;
       }
       label{
           color: honeydew;
       }
    </style>
</head>
<body>
    <div class="box">
        <h2>用户登录</h2>
        <form class="layui-form" action="">
            <div class="layui-form-item">
              <label class="layui-form-label">用户名</label>
              <div class="layui-input-block">
               <input type="text" name="username" required  lay-verify="required" placeholder="请输入用户名" autocomplete="off" class="layui-input">
              </div>
            </div>
            <div class="layui-form-item">
              <label class="layui-form-label">密码</label>
              <div class="layui-input-block">
               <input type="password" name="password" required  lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
              </div>
            </div>
            
            <div class="layui-form-item">
              <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="formDemo">登录</button>
              </div>
            </div>
          </form>

          <script>
            layui.use( function(){
              var form = layui.form;
              var $ = layui.jquery;
              var layer = layui.layer
         // 监听提交
            form.on('submit(formDemo)', function(data){
                $.post({
                  url:'/admin/dologin',
                  data:data.field,
                  success:function(res){
                    if(res.code === 0){
                      window.sessionStorage.admin = data.field.username
                      window.location.href = "/admin"
                    }else{
                      alert("登陆失败，请检查您的用户名")
                    }
                  }
                })
                return false;
            });
            });
            </script>
    </div>
</body>
</html>